//
//  LSZAudioDetailsViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/30.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZAudioDetailsViewController.h"

@interface LSZAudioDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView * tableViewAudioDetails;

@property(nonatomic,strong) NSMutableArray * mutArrayData;
@end

@implementation LSZAudioDetailsViewController
-(void)getDataDetails
{
    [LSZRequestDicData threeInterfaceForData:self.id_id :^(BOOL isOk, NSString * string, LSZTertiaryInterfaceManager * manager) {
        if(isOk == YES){
            [self.mutArrayData addObjectsFromArray:manager.arrayData];
            [self.tableViewAudioDetails reloadData];
        }else{
            if ([string isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZAudioDetailsViewController"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:string];
            }
        }
    }];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZAudioDetailsViewController"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.name;
    [self addNotificationCenter];
    [self getDataDetails];
    self.mutArrayData = [[NSMutableArray alloc]init];
    [self.tableViewAudioDetails registerClass:[LSZBasicInformationManager class] forHeaderFooterViewReuseIdentifier:@"LSZBasicInformationManager"];
    [self.tableViewAudioDetails registerClass:[LSZAudioDetailsTableViewCell class] forCellReuseIdentifier:@"LSZAudioDetailsTableViewCell"];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    CGFloat height = [LSZSpecialPackaging getHeightOfText:ScreenWidth-40 height:ScreenHeight font:14.5 :self.summary];
    return 165+height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZTertiaryInterfaceMg * mg = nil;
    mg = self.mutArrayData[indexPath.row];
    CGFloat height = [LSZSpecialPackaging getHeightOfText:ScreenWidth-80 height:ScreenHeight font:15 :mg.name];
    return 33+15+height;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutArrayData.count;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LSZBasicInformationManager * header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZBasicInformationManager"];
    [header.imageViewIcon sd_setImageWithURL:[NSURL URLWithString:self.coverUrl] placeholderImage:[UIImage imageNamed:@"默认"]];
    header.labelTitle.text = self.name;
    header.labelContent.text = self.summary ;
    CGFloat height = [LSZSpecialPackaging getHeightOfText:ScreenWidth-40 height:ScreenHeight font:14.5 :self.summary];
    CGRect rect = header.labelContent.frame;
    rect.size.height = height;
    header.labelContent.frame = rect;
    return header;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZAudioDetailsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZAudioDetailsTableViewCell" forIndexPath:indexPath];
    if(self.mutArrayData.count > indexPath.row){
        LSZTertiaryInterfaceMg * mg = nil;
        mg = self.mutArrayData[indexPath.row];
        cell.tertiaryInterfaceMg = mg;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.mutArrayData.count > indexPath.row) {
        LSZAudioPlaybackInterfaceVC * vc = [[LSZAudioPlaybackInterfaceVC alloc]init];
        vc.mutArrayData = self.mutArrayData;
        vc.numberRow = indexPath.row;
        [self.navigationController pushViewController:vc animated:NO];
    }
}
-(UITableView *)tableViewAudioDetails
{
    if (_tableViewAudioDetails == nil) {
        _tableViewAudioDetails = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
        _tableViewAudioDetails.delegate = self;
        _tableViewAudioDetails.dataSource = self;
        _tableViewAudioDetails.estimatedRowHeight=0;
        _tableViewAudioDetails.estimatedSectionFooterHeight =0;
        _tableViewAudioDetails.estimatedSectionHeaderHeight =0;
        [_tableViewAudioDetails setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewAudioDetails];
    }
    return _tableViewAudioDetails;
}

@end
